%% -*- coding: utf-8 -*-

%% @doc JSONでコンテキストを与える場合のテスト
%%
-module(t_json).
-import(templ, [init/0,init/1,process/1,process/2,process/3,process/4]).

-include_lib("eunit/include/eunit.hrl").

process_expr_test_() ->
	init("{\"title\":\"My Homepage\", \"names\":[\"John\",\"Gary\",\"Gregg\",\"James\"],
           \"ten\": 10, \"bool\":true\}"),

	[?_assertMatch("Welcome to My Homepage", 
				   process("Welcome to {title}")),
	 ?_assertMatch("Hello John",
				   process("Hello {names[1]}")),

	 ?_assertMatch("77 121",
				   process("{title[1]} {title[2]}")),

	 ?_assertThrow({{templel_parse_handler,einval},{"names",_},"out of bound"}, 
				   process("{names[10]}")),
	 ?_assertThrow({{templel_parse_handler,einval},{{value,"ten",10},1}},
				   process("{ten[1]}")),
	 ?_assertThrow({{templel_parse_handler,einval},{{value,"bool",true},1}},
				   process("{bool[1]}"))
	].
